home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / P3DMLOCK.AS_ / p3dmlock.asp
Encoding:
Text File  |  2003-02-21  |  10.3 KB  |  377 lines

  1. <%@ Language=VBScript   %>
  2. <%    Option Explicit     %>
  3. <%
  4.     '-------------------------------------------------------------------------
  5.     ' POP3 Mail Add-in - Domains - Lock
  6.     ' Copyright (C) Microsoft Corporation.  All rights reserved.
  7.     '-------------------------------------------------------------------------
  8. %>
  9.     <!-- #include virtual="/admin/inc_framework.asp" -->
  10.     <!-- #include virtual="/admin/ots_main.asp" -->
  11.     <!-- #include file="p3cminc.asp" -->
  12. <%
  13.  
  14.     '-------------------------------------------------------------------------
  15.     ' Global Constants
  16.     '-------------------------------------------------------------------------
  17.     Dim SOURCE_FILE
  18.     SOURCE_FILE = SA_GetScriptFileName()
  19.     
  20.     Const FLD_NAME = "fldName"
  21.  
  22.  
  23.     '-------------------------------------------------------------------------
  24.     ' Global Variables
  25.     '-------------------------------------------------------------------------
  26.     Dim g_page
  27.     
  28.     Dim g_rgFailures
  29.     Dim g_nFailures
  30.     g_nFailures = 0
  31.     
  32.     Dim g_strLockFlag
  33.     If (Request.QueryString(PARAM_LOCKFLAG).Count > 0) Then
  34.         g_strLockFlag = UCase(Request.QueryString(PARAM_LOCKFLAG).Item(1))
  35.     ElseIf (Request.Form(PARAM_LOCKFLAG).Count > 0) Then
  36.         g_strLockFlag = UCase(Request.Form(PARAM_LOCKFLAG).Item(1))
  37.     Else
  38.         ' Default to locking
  39.         g_strLockFlag = LOCKFLAG_LOCK
  40.     End If
  41.     
  42.     
  43.     '----------------------------------------------------------------------
  44.     ' Global Localized Strings
  45.     '----------------------------------------------------------------------
  46.     Dim l_strPageTitle
  47.     ' The title will only be shown in the case of an error, so always set
  48.     ' the error title.
  49.     If (LOCKFLAG_LOCK = g_strLockFlag) Then
  50.         l_strPageTitle = GetLocString(RES_DLL_NAME, _
  51.                                       POP3_PAGETITLE_DOMAINS_LOCKERROR, _
  52.                                       "")
  53.     Else
  54.         l_strPageTitle = GetLocString(RES_DLL_NAME, _
  55.                                       POP3_PAGETITLE_DOMAINS_UNLOCKERROR, _
  56.                                       "")
  57.     End If
  58.  
  59.     Dim l_strLockErrorPrompt
  60.     l_strLockErrorPrompt    = GetLocString(RES_DLL_NAME, _
  61.                                            POP3_PROMPT_DOMAINS_LOCKERROR, _
  62.                                            "")
  63.     
  64.     Dim l_strUnlockErrorPrompt
  65.     l_strUnlockErrorPrompt    = GetLocString(RES_DLL_NAME, _
  66.                                            POP3_PROMPT_DOMAINS_UNLOCKERROR, _
  67.                                            "")
  68.     
  69.     Dim l_strRetryPrompt
  70.     l_strRetryPrompt        = GetLocString(RES_DLL_NAME, _
  71.                                            POP3_PROMPT_DOMAINS_LOCKRETRY, _
  72.                                            "")
  73.  
  74.  
  75.     '**********************************************************************
  76.     '*                        E N T R Y   P O I N T
  77.     '**********************************************************************
  78.     
  79.     '
  80.     ' Attempt the operation.
  81.     '
  82.     If (AtFirstYouSucceed(g_strLockFlag)) Then
  83.         ' The operation succeeded and code has been output to redirect
  84.         ' back to the caller.
  85.         Response.End()
  86.     Else
  87.         ' The operation failed, so display the retry page.
  88.         Call SA_CreatePage(l_strPageTitle, "", PT_PROPERTY, g_page)
  89.         Call SA_ShowPage  (g_page)
  90.     End If
  91.  
  92.  
  93.     '**********************************************************************
  94.     '*                H E L P E R  S U B R O U T I N E S 
  95.     '**********************************************************************
  96.     Function AtFirstYouSucceed(strLockFlag)
  97.         On Error Resume Next
  98.         
  99.         AtFirstYouSucceed = false
  100.         
  101.         '
  102.         ' If this is the first time the page has been loaded, try to
  103.         ' execute the request.  Otherwise, we won't have the correct
  104.         ' return URL, so let the normal page events handle the request.
  105.         '
  106.         If (Request.Form(FLD_NAME).Count <> 0) Then
  107.             Exit Function
  108.         End If
  109.  
  110.         Dim rgDomainsTable
  111.         rgDomainsTable = GetDomainList()
  112.     
  113.         If (Err.number <> 0) Then
  114.             Call SA_SetErrMsg( HandleUnexpectedError() )
  115.             Exit Function
  116.         End If
  117.         
  118.         Call LockDomains(rgDomainsTable, strLockFlag)
  119.         
  120.         If (g_nFailures = 0) Then
  121.             '
  122.             ' The domains were successfully un/locked.  Redirect back to
  123.             ' the OTS.
  124.             '
  125. %>
  126.             <SCRIPT LANGUAGE="Javascript" FOR="window" EVENT="onload">
  127.                 try
  128.                 {
  129.                     // Hide the footer to avoid "Action Cancelled" page from briefly displaying.
  130.                     top.document.getElementsByTagName("frameset").item(0).rows = "*,0";
  131.                     top.location.href = "<%=Server.HTMLEncode(Request.QueryString("ReturnURL").Item(1))%>";
  132.                 }
  133.                 catch(e)
  134.                 {
  135.                     // Nothing we can do.
  136.                 }
  137.             </SCRIPT>
  138. <%
  139.             AtFirstYouSucceed = true
  140.         End If
  141.     End Function
  142.     
  143.     '---------------------------------------------------------------------
  144.     ' GetDomainList
  145.     '---------------------------------------------------------------------
  146.     Function GetDomainList()
  147.         Dim rgDomains
  148.         
  149.         '
  150.         ' First, check the form data.
  151.         '
  152.         Dim iRow
  153.         Dim nRows
  154.         nRows = Request.Form(FLD_NAME).Count
  155.         
  156.         If (nRows <> 0) Then
  157.             ReDim rgDomains(nRows, 0)
  158.  
  159.             '
  160.             ' Iterate over the form data.
  161.             '
  162.             For iRow = 1 to nRows
  163.                 rgDomains(iRow, 0) = Request.Form(FLD_NAME).Item(iRow)
  164.             Next
  165.         Else
  166.             '
  167.             ' Form data was empty -- try the OTS data.
  168.             '
  169.             nRows = OTS_GetTableSelectionCount("")
  170.  
  171.             ReDim rgDomains(nRows, 0)
  172.  
  173.             For iRow = 1 to nRows
  174.                 If (Not OTS_GetTableSelection("", iRow, rgDomains(iRow, 0))) Then
  175.                     Call SA_TraceErrorOut(SOURCE_FILE, _
  176.                                           "Failed to get OTS selection.")
  177.  
  178.                     Err.Raise(-1)
  179.                 End If
  180.             Next
  181.         End If
  182.         
  183.         GetDomainList = rgDomains
  184.     End Function
  185.     
  186.     '---------------------------------------------------------------------
  187.     ' LockDomains
  188.     '---------------------------------------------------------------------
  189.     Function LockDomains(rgDomainsTable, strLockFlag)
  190.         On Error Resume Next
  191.  
  192.         Dim bLock
  193.         If (LOCKFLAG_LOCK = strLockFlag) Then
  194.             bLock = true
  195.         Else
  196.             bLock = false
  197.         End If
  198.         
  199.         Dim oConfig
  200.         Set oConfig = Server.CreateObject("P3Admin.P3Config")
  201.         
  202.         Dim colDomains
  203.         Set colDomains = oConfig.Domains
  204.  
  205.         Dim nRows
  206.         nRows = UBound(rgDomainsTable, 1)
  207.         
  208.         ' Create an array to hold the names of any domains that could
  209.         ' not be un/locked.
  210.         ReDim g_rgFailures(nRows, 0)
  211.         g_nFailures = 0
  212.  
  213.  
  214.         '
  215.         ' Store the error to report at the end of this method.  We don't
  216.         ' want to stop processing, because the list of failures needs to
  217.         ' be filled.
  218.         '
  219.         Dim nErr
  220.         nErr = Err.number
  221.         Err.Clear()
  222.  
  223.         '
  224.         ' Iterate over the selected domains and un/lock them.
  225.         '
  226.         Dim iRow
  227.         For iRow = 1 to nRows
  228.             colDomains.Item(rgDomainsTable(iRow, 0)).Lock = bLock
  229.             If (Err.number <> 0) Then
  230.                 Call SA_TraceErrorOut(SOURCE_FILE, _
  231.                                       "Failed to lock domain " & rgDomainsTable(iRow, 0) & ": " & CStr(Hex(Err.number)) & ": " & Err.Description)
  232.                 Err.Clear()
  233.                     
  234.                 g_nFailures = g_nFailures + 1
  235.                 g_rgFailures(g_nFailures, 0) = rgDomainsTable(iRow, 0)
  236.             End If
  237.         Next
  238.         
  239.         If (nErr <> 0) Then
  240.             Call SA_SetErrMsg( HandleUnexpectedError() )
  241.             Exit Function
  242.         End If
  243.  
  244.     End Function
  245.     
  246.     '---------------------------------------------------------------------
  247.     ' OutputNameList
  248.     '---------------------------------------------------------------------
  249.     Sub OutputNameList(rgDomainsTable, nRows)
  250.         '
  251.         ' Sort the names.
  252.         '
  253.         Call SAQuickSort(rgDomainsTable, 1, nRows, 1, 0)
  254.         
  255.         '
  256.         ' Output the names in a bulleted list.
  257.         '
  258.         Response.Write("<UL>" & vbCrLf)
  259.         
  260.         Dim iRow
  261.         For iRow = 1 to nRows
  262. %>
  263.             <LI><%=Server.HTMLEncode(rgDomainsTable(iRow, 0))%></LI>
  264.             <INPUT TYPE="hidden" NAME="<%=FLD_NAME%>"
  265.                    VALUE="<%=Server.HTMLEncode(rgDomainsTable(iRow, 0))%>">
  266. <%
  267.         Next
  268.  
  269.         Response.Write("</UL>" & vbCrLf)
  270.     End Sub
  271.     
  272.     '---------------------------------------------------------------------
  273.     ' ServeCommonJavaScript
  274.     '---------------------------------------------------------------------
  275.     Function ServeCommonJavaScript()
  276.     %>
  277.         <script language="JavaScript" src="../inc_global.js">
  278.         </script>
  279.         <script language="JavaScript">
  280.         
  281.         function Init(){}
  282.         function ValidatePage(){return true;}
  283.         function SetData(){}
  284.     
  285.         </script>
  286.     <%
  287.     End Function
  288.  
  289.  
  290.     '**********************************************************************
  291.     '*                    E V E N T   H A N D L E R S
  292.     '**********************************************************************
  293.     
  294.     '---------------------------------------------------------------------
  295.     ' OnInitPage
  296.     '---------------------------------------------------------------------
  297.     Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  298.         OnInitPage = TRUE
  299.     End Function
  300.     
  301.     '---------------------------------------------------------------------
  302.     ' OnServePropertyPage
  303.     '---------------------------------------------------------------------
  304.     Public Function OnServePropertyPage(ByRef PageIn, ByRef EventArg)
  305.         On Error Resume Next
  306.         
  307.         OnServePropertyPage = TRUE
  308.  
  309.         Dim rgDomainsTable
  310.  
  311.         '
  312.         ' Emit Javascript functions required by Web Framework
  313.         Call ServeCommonJavaScript()
  314.  
  315. %>
  316.         <INPUT TYPE="hidden" NAME="<%=PARAM_LOCKFLAG%>" VALUE="<%=g_strLockFlag%>">
  317. <%
  318.  
  319.         If (g_nFailures < 1) Then
  320.             Call SA_TraceErrorOut(SOURCE_FILE, _
  321.                                   "Page was loaded even though no domains failed!")
  322.         End If
  323.         
  324.         '
  325.         ' Output the error prompt and sorted list of failed domains.
  326.         '
  327.         If (g_strLockFlag = LOCKFLAG_LOCK) Then
  328.             Response.Write(l_strLockErrorPrompt & "<BR>" & vbCrLf)
  329.         Else
  330.             Response.Write(l_strUnlockErrorPrompt & "<BR>" & vbCrLf)
  331.         End If
  332.  
  333.         Call OutputNameList(g_rgFailures, g_nFailures)
  334.         Response.Write("<BR>" & l_strRetryPrompt & vbCrLf)
  335.         
  336.         OnServePropertyPage = TRUE
  337.  
  338.         If (Err.number <> 0) Then
  339.             Call SA_SetErrMsg( HandleUnexpectedError() )
  340.         End If
  341.     End Function
  342.  
  343.     '---------------------------------------------------------------------
  344.     ' OnPostBackPage
  345.     '---------------------------------------------------------------------
  346.     Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  347.             OnPostBackPage = TRUE
  348.     End Function
  349.  
  350.     '---------------------------------------------------------------------
  351.     ' OnSubmitPage
  352.     '---------------------------------------------------------------------
  353.     Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  354.         On Error Resume Next
  355.         
  356.         OnSubmitPage = FALSE
  357.         
  358.         Dim rgDomainsTable
  359.         rgDomainsTable = GetDomainList()
  360.         
  361.         Call LockDomains(rgDomainsTable, g_strLockFlag)
  362.  
  363.         If (g_nFailures > 0) Then
  364.             OnSubmitPage = FALSE
  365.         Else
  366.             OnSubmitPage = TRUE
  367.         End If
  368.     End Function
  369.     
  370.     '---------------------------------------------------------------------
  371.     ' OnClosePage
  372.     '---------------------------------------------------------------------
  373.     Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  374.         OnClosePage = TRUE
  375.     End Function
  376. %>
  377.